package com.luo.wheresmytakeaway.controller;

import com.luo.wheresmytakeaway.pojo.Order;
import com.luo.wheresmytakeaway.pojo.Results;
import com.luo.wheresmytakeaway.service.OrderService;

import com.luo.wheresmytakeaway.utils.GieUserId;

import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
public class OrderController {
    @Autowired
    private OrderService orderService;


    @GetMapping("/orders")
    public Results getOrderList(HttpServletRequest request) {
        Integer uid = GieUserId.getUserId(request);
        return Results.success(orderService.getOrderService(uid));
    }

    @PostMapping("/orders")
    public Results addOrder(@RequestBody Order order) {
        orderService.addOrder(order);
        return Results.success();
    }

    @DeleteMapping("/orders/{id}")
    public Results deleteOrder(@PathVariable List<Integer> id) {
        orderService.deleteOrder(id);
        return Results.success();
    }

    @GetMapping("/orders/{status}")
    public Results getOrderListByStatus(@PathVariable Integer status, HttpServletRequest request) {
        Integer uid = GieUserId.getUserId(request);
        return Results.success(orderService.getOrderListByStatus(status, uid));
    }
}
